/*
 * @Author: SeonHu
 * @Date: 2025-09-16 14:44:19
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-09-23 14:55:10
 * @FilePath: \bg-vben\src\api\authorization\admin\module\index.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import type { FunctionOutputDtoSimple } from '@/api/authorization/admin/function/model';

import type { ModuleOutputDto } from './model';

import type { ErrorMessageMode, PageData } from '#/request';

import { request } from '@/utils/request/axios';

import { PageRequest } from '#/request';

/** 管理-模块信息枚举 */
enum Api {
  /** 读取模块信息 */
  Read = '/api/admin/module/read',
  /** 读取模块[用户]树数据 */
  ReadUserModules = '/api/admin/module/readUserModules',
  /** 读取模块[角色]树数据 */
  ReadRoleModules = '/api/admin/module/readRoleModules',
  /** 读取模块功能 */
  ReadFunctions = '/api/admin/module/readFunctions',
}

// #region 读取模块信息
/**
 * 读取模块信息
 * @param mode 错误消息模型
 */
export function readModules(mode: ErrorMessageMode = 'message') {
  return request.post<ModuleOutputDto[]>(
    {
      url: Api.Read,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取模块[用户]树数据
/**
 * 读取模块[用户]树数据
 * @param userId 用户编号
 * @param mode 错误消息模型
 */
export function readUserModules(userId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<any[]>(
    {
      url: Api.ReadUserModules,
      params: { userId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取模块[角色]树数据
/**
 * 读取模块[角色]树数据
 * @param roleId 角色编号
 * @param mode 错误消息模型
 */
export function readRoleModules(roleId: bigint | string, mode: ErrorMessageMode = 'message') {
  return request.get<any[]>(
    {
      url: Api.ReadRoleModules,
      params: { roleId },
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取模块功能
/**
 * 读取模块功能
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readModuleFunctions(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<FunctionOutputDtoSimple>>(
    {
      url: Api.ReadFunctions,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
